﻿using ProjectFootball.MVC.Foundation;
using ProjectFootball.MVC.Models.RepositoryProviders;
using System.Linq;
using System.Web.Mvc;

namespace ProjectFootball.MVC.Controllers
{
    public class JsonController : BaseController
    {
        #region Constructor
        public JsonController(IRepositoryProvider provider)
            :base(provider)
        {
        }
        #endregion

        #region CodePicker
        [OutputCache(Duration = 0)]
        public JsonResult GetCompetitionCodePickerData()
        {
            return Json(Provider.CompetitionRepository.GetCodePickerData(), JsonRequestBehavior.AllowGet);
        }

        [OutputCache(Duration = 0)]
        public JsonResult GetCountryCodePickerData()
        {
            return Json(Provider.CountryRepository.GetCodePickerData(), JsonRequestBehavior.AllowGet);
        }

        [OutputCache(Duration = 0)]
        public JsonResult GetVenueCodePickerData()
        {
            return Json(Provider.VenueRepository.GetCodePickerData(), JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region Autocomplete
        [OutputCache(Duration = 0)]
        public JsonResult GetCombinedAutoCompleteList(string text)
        {
            var returnValue = Provider.CompetitionRepository.GetAutoCompleteList(User, text)
                .Concat(Provider.CountryRepository.GetAutoCompleteList(User, text))
                .Concat(Provider.PersonRepository.GetAutoCompleteList(User, text))
                .Concat(Provider.TeamVersionRepository.GetAutoCompleteList(User, text))
                .Concat(Provider.VenueRepository.GetAutoCompleteList(User, text));

            return Json(returnValue, JsonRequestBehavior.AllowGet);
        }

        [OutputCache(Duration = 0)]
        public JsonResult GetCountryAutoCompleteList(string text)
        {
            return Json(Provider.CountryRepository.GetAutoCompleteList(User, text), JsonRequestBehavior.AllowGet);
        }

        [OutputCache(Duration = 0)]
        public JsonResult GetPersonAutoCompleteList(string text)
        {
            return Json(Provider.PersonRepository.GetAutoCompleteList(User, text), JsonRequestBehavior.AllowGet);
        }

        [OutputCache(Duration = 0)]
        public JsonResult GetVenueAutoCompleteList(string text)
        {
            return Json(Provider.VenueRepository.GetAutoCompleteList(User, text), JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}
